/**
 * 
 */
package com.yidin.lsc;

import java.util.List;

import com.yidin.entry.NotificationCenterEntry;
import com.yidin.lsc.AddressListAdapter.ViewHolder;
import com.yidin.util.NetImageBase;
import com.yidin.util.imageCallback;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 通知中心适配器
 * 
 * @author cola
 * 
 */
public class NotificationCenterAdapter extends MyBaseAdapter {
	private Context context;
	private List<NotificationCenterEntry> userInfos;

	public NotificationCenterAdapter(List<NotificationCenterEntry> userInfo,
			Context context) {
		super(userInfo, context);
		this.context = context;
		this.userInfos = userInfo;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return userInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return userInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;
		final int i = position;
		final ImageView icon;
		ViewHolder holder = null;
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.commetitem,
					null);

			holder = new ViewHolder();
			view.setTag(holder);
			holder.tv_catalog = (TextView) view.findViewById(R.id.adress_name);
			holder.tv_nick = (TextView) view.findViewById(R.id.address_im);
			holder.tv_time = (TextView) view.findViewById(R.id.pro_right);
			holder.icon = (ImageView) view.findViewById(R.id.pro_gameico);
			icon = holder.icon;
			Bitmap bm2 = null;
			NetImageBase n = new NetImageBase();
			if (this.userInfos.get(position).PictureUrl != null) {// 请求图标
				bm2 = n.getLogoBitmap(handler, context,
						this.userInfos.get(position).PictureUrl,
						new imageCallback() {
							public void getImage(Bitmap bm) {
								// TODO Auto-generated method stub
								if (bm != null) {
									icon.setImageBitmap(bm);
									getIsSelected().put(i, bm);
								}
							}
						});

			}
			if (bm2 != null) {
				bm2 = n.getLocalBitmap(null, context,
						this.userInfos.get(position).PictureUrl, 450, 170);
				holder.icon.setImageBitmap(bm2);
				getIsSelected().put(i, bm2);
			}
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_catalog.setText(userInfos.get(position).Title);
		holder.tv_nick.setText(userInfos.get(position).Content);
		holder.tv_time.setText(userInfos.get(position).OpTime);
		holder.tv_time.setBackgroundDrawable(null);
		if (getIsSelected().get(position) != null)
			holder.icon.setImageBitmap(getIsSelected().get(position));
		return view;
	}

	class ViewHolder {

		TextView tv_catalog;
		TextView tv_nick;
		TextView tv_time;
		ImageView icon;
	}
}
